package data;

import java.util.ArrayList;

import core.Log;

public class EventList
{
	private ArrayList<Event> eventList;
	private String listName;

	public EventList() {
		this("default");
		Log.debug("EventList: Entering default constructor" );
		Log.warn("EventList: Default constructor used. creates a list with name *default*");
	}

	public int size() {
		Log.debug("EventList: Entering size" );
		return eventList.size();
	}
	
	public EventList(String name) {
		Log.debug("EventList: Entering constructor with name as param" );
		eventList = new ArrayList<Event>();
		listName = name;
	}

	public void addEvent(Event e) {
		Log.debug("EventList: Entering addEvent" );
		eventList.add(e);
	}

	public boolean replace(Event from, Event to) {
		Log.debug("EventList: Entering replace" );
		//returns false if event is not in the list
		if (eventList.remove(from)) {
			eventList.add(to);
			Log.warn("EventList: Event was replaced with new event by replace function");
			return true;
		}
		Log.warn("EventList: replace function was unable to replace event");
		return false;
	}

	public void remove(Event e) {
		Log.debug("EventList: Entering remove" );
		eventList.remove(e);
	}

	public String getName() {
		Log.debug("EventList: Entering getName" );
		return listName;
	}

	public void setName(String name) {
		Log.debug("EventList: Entering setName" );
		listName = name;
	}

	public ArrayList<Event> getEvents() {
		Log.debug("EventList: Entering getEvents" );
		return eventList;
	}

	public void setEvents(ArrayList<Event> e) {
		Log.debug("EventList: Entering setEvents" );
		eventList = e;
	}


	public boolean equals(Object o) {
		Log.debug("EventList: Entering equals" );
		if(!(o instanceof EventList)) {
			Log.warn("EventList: equals function failed because object entered was not a valid EventList");
			return false;
		}

		EventList compareTo = (EventList)o;

		if (this.getName().equals(compareTo.getName()) && this.eventList.size() == compareTo.getEvents().size()) {
			for (int i = 0 ; i < this.eventList.size(); i++) {
				if (!this.eventList.get(i).equals(compareTo.getEvents().get(i))) {
					Log.warn("EvenList: equals function returned false because two objects were not the same");
					return false;
				}
			}
			Log.debug("EventList: equals function returned true.Objects are identical");
			return true;
		}
		Log.warn("EventList: equals function reached default output of false because all other if conditions failed");
		return false;
	}
	
	public boolean contains(Event event) {
		Log.debug("EventList: Entering contains" );
		return eventList.contains(event);
	}
}

